package com.cqw.order.controller;

import com.cqw.common.BaseResponse;
import com.cqw.order.domain.Spu;
import com.cqw.order.service.SpuService;
import com.cqw.validate.Add;
import com.cqw.validate.Update;
import com.cqw.vo.order.SpuReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-07-12 17:35
 * @Description: spu
 */
@RestController
@RequestMapping("/spu")
@Slf4j
@Api(tags = "spu管理")
public class SpuController {


    @Resource
    private SpuService spuService;


    @GetMapping("/page")
    @ApiOperation(value = "分页查询SPU")
    public BaseResponse getSpuPage(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        List<Spu> list = spuService.getSpuPage(pageIndex, pageSize);
        return BaseResponse.success(list);
    }


    @PostMapping("/create")
    @ApiOperation(value = "新建spu")
    public BaseResponse createSpu(@RequestBody @Validated(Add.class) SpuReq spuReq) {
        Spu spu = spuService.createSpu(spuReq);
        return BaseResponse.success(spu);
    }


    @PostMapping("/update")
    @ApiOperation(value = "修改spu")
    public BaseResponse updateSpu(@RequestBody @Validated(Update.class) SpuReq spuReq) {
        Spu spu = spuService.updateSpu(spuReq);
        return BaseResponse.success(spu);
    }


}
